package game.shared;

import game.entity.AbsAnimation;

import java.util.ArrayList;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class Resources {
	private static ArrayList<TextureRegion> listTextureRegions;
	private static ArrayList<Texture> listTextures;
	private static ArrayList<String> listFilePaths;
	private static ArrayList<Integer> listIDs;
	private static int nLoad = 0;
	
	public static boolean LoadResource(String configFilePath)
	{
		if(nLoad >= 1)
			return true;
		listFilePaths = new ArrayList<String>();
		listTextures = new ArrayList<Texture>();
		listTextureRegions = new ArrayList<TextureRegion>();
		listIDs = new ArrayList<Integer>();
		nLoad = 1;
		
		try
		{
			FileHandle file = Gdx.files.internal(configFilePath);
			String strCfg = file.readString();
			String[] lines = strCfg.split("\r\n");
			for(int i=0; i<lines.length;)
			{
				String[] info = lines[i].split(";");
				int n = Integer.parseInt(info[0]) + i;
				String path = info[1];
				i++;
				for(; i<=n; i++)
				{
					String[] values = lines[i].split(";");
					int id = Integer.parseInt(values[0]); 	// resource id	
					int x = Integer.parseInt(values[1]); 	//x
					int y = Integer.parseInt(values[2]); 	//y
					int w = Integer.parseInt(values[3]); 	//w
					int h = Integer.parseInt(values[4]); 	//h
					
					listIDs.add(id);
					Texture texture = getTexture(path);
					listTextureRegions.add(new TextureRegion(texture, x, y, w, h));
				}
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
			return false;
		}
		
		return false;
	}
	
	private static Texture getTexture(String filePath)
	{
		int i=0;	
		for (; i<listFilePaths.size(); i++)
		{
			if(listFilePaths.get(i) ==filePath )
				return listTextures.get(i);
		}
		listFilePaths.add(filePath);
		listTextures.add(new Texture(filePath));
		return listTextures.get(i);
	}
	
	public static TextureRegion getTextureRegion(int id)
	{
		int i=0;	
		for (; i<listIDs.size(); i++)
			if(listIDs.get(i) == id)
				return listTextureRegions.get(i);
		return null;
	}
	
	public static final int BUTTON_1 			= 1;
	public static final int BUTTON_2 			= 2;
	public static final int SNOW 				= 3;
	public static final int WATERMARK 			= 4;
	public static final int BUNKER 				= 5;
	public static final int BODER				= 6;
	public static final int BUTTON_MID			= 7;
	public static final int BUTTON_CLOUD_FIRE	= 8;
	public static final int HP_TEXTURE			= 9;
	public static final int MANA_TEXTURE		= 10;
	public static final int PROCESS_TEXTURE		= 11;
	public static final int SLOTS_LEFT		= 12;
	public static final int SLOTS_RIGHT		= 13;
	
	public static final int MENU_NEWGAME 		= 105;
	public static final int MENU_CONTINUE_GAME 	= 106;
	public static final int MENU_OPTION			= 107;
	public static final int MENU_CREDIT 		= 108;
	public static final int MENU_SHOP 			= 109;
	public static final int MENU_RESUME			= 110;
	public static final int MENU_EXIT 			= 111;
	public static final int MENU_NEWGAME_2 		= 112;
	public static final int MENU_CONTINUE_GAME_2= 113;
	public static final int MENU_OPTION_2 		= 114;
	public static final int MENU_CREDIT_2		= 115;
	public static final int MENU_SHOP_2 		= 116;
	public static final int MENU_RESUME_2		= 117;
	public static final int MENU_EXIT_2 		= 118;
	public static final int MENU_MENU 			= 119;
	public static final int MENU_MENU_2 		= 120;
	public static final int MENU_OTHER 			= 121;
	public static final int MENU_OTHER_2		= 122;
	public static final int BUTTON_BUY_1			= 123;
	public static final int BUTTON_BUY_2			= 124;
	public static final int BUTTON_SELL_1			= 125;
	public static final int BUTTON_SELL_2			= 126;
	public static final int TG_TAB_1			= 127;
	public static final int TG_TAB_2			= 128;
	
	public static final int ROCKET_1			= 200;
	
	public static final int ITEMS_HP_4			= 300;
	public static final int AMMUNITION_1		= 301;
	
	public static final int TAB_1				= 401;
	public static final int TAB_2				= 402;
	public static final int TAB_3				= 403;
	public static final int TAB_4				= 404;
	public static final int TAB_1_2				= 405;
	public static final int TAB_2_2				= 406;
	public static final int TAB_3_2				= 407;
	public static final int TAB_4_2				= 408;
	public static final int HP_1				= 409;
	public static final int HP_2				= 410;
	public static final int HP_3				= 411;
	public static final int HP_4				= 412;
	public static final int MANA_1				= 413;
	public static final int MANA_2				= 414;
	public static final int MANA_3				= 415;
	public static final int MANA_4				= 416;
	public static final int GEM_RED_1			= 417;
	public static final int GEM_RED_2			= 418;
	public static final int GEM_RED_3			= 419;
	public static final int GEM_RED_4			= 420;
	public static final int GEM_BLUE_1			= 421;
	public static final int GEM_BLUE_2			= 422;
	public static final int GEM_BLUE_3			= 423;
	public static final int GEM_BLUE_4			= 424;
	
	public static final int BG_SELECT_LEVEL		= 500;
	public static final int LOCK_LEVEL			= 501;
}
